package com.cl.code.database.mybatis.module.page;

import com.github.pagehelper.PageInfo;
import lombok.Getter;

import java.util.Collections;
import java.util.List;

/**
 * 分页结果
 *
 * @author chengliang
 * @since 1.0.0
 */
@Getter
public class PageResult<T> {

    private final Long total;

    private final List<T> list;

    private PageResult(Long total, List<T> list) {
        this.total = total;
        this.list = list;
    }

    public static <T> PageResult<T> build(List<T> list) {
        PageInfo<T> pageInfo = PageInfo.of(list);
        return build(pageInfo.getTotal(), list);
    }

    public static <T> PageResult<T> build(Long total, List<T> list) {
        return new PageResult<>(total, list);
    }

    public static <T> PageResult<T> empty() {
        return new PageResult<T>(0L, Collections.emptyList());
    }

}
